<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
    <title><spring:message code="title.user"/></title>
    <script type="text/javascript">
        var datagrid;
        var message =$.messager;
        var operateDialog;
        var title="";
        var href ="";
        $(function() {
            datagrid=$('#datagrid').datagrid({
                url : '${path}/sys/user/ajaxList.do',
                queryParams: imonJYRH.serializeObject($("#tableForm *"))
            });
        });
        function stateFormatter(value,row,index){
        <c:forEach var="dict" items="${dictRecordStatusList}">
            if(row['state']=='${dict.code}'){
                if(row['state']=='9'){
                    return '<span style="color:red">${dict.name}</span>'
                }else{
                    return '${dict.name}';
                }
            }
        </c:forEach>
        }
        //子页面返回方法
        function returnResult(){
            operateDialog.dialog('close');
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('reload');
        }
        //判断选择单据是否是一条
        function isChooseOne(rows){
            var flag = false;
            if(rows.length >1 ) {
                message.show({
                    msg : "<spring:message code='msg.choose' arguments='"+rows.length+"'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            } else if (rows.length == 0) {
                message.show({
                    msg : "<spring:message code='msg.please.choose'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            }else{
                flag = true;
            }
            return flag;
        }
        function append() {
    		//弹出层的相关参数
        	operateDialog = $("#operateDialog").dialog({
    			title : title,collapsible:true,maximizable:true,
    			width : 600,
        		height: 400,
    			buttons : [{
    				iconCls:"icon-save",
    				text : '<spring:message code='button.save'/>',
    				handler : function() {
    					$("#operateIFrame")[0].contentWindow.manageForm(message);
    				}
    			},{
    				iconCls:"icon-no",
    				text : '<spring:message code='button.close'/>',
    				handler : function() {
    					//关闭按钮的时候进行关闭按钮
    					operateDialog.dialog('close');
    				}
    			}]
    		});
        	$("#operateIFrame")[0].src=imonJYRH.url(href); 
        	operateDialog.dialog('open');
        	imonJYRH.showZone();
        }
        function editRoles(){
       	 	var rows = datagrid.datagrid("getSelections");
            if(!isChooseOne(rows)){return;}
        	title = "分配角色";
        	href  = "${path}/sys/user/modeifyRoleUI.do?id="+rows[0]['id'];
        	append();
        }
        function getSelectedIds(){
            var rows = datagrid.datagrid("getSelections");
            if (rows.length > 0) {
                var ids = [];
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                return ids;
            }else{
                $.messager.alert('<spring:message code='msg.error'/>','<spring:message code='msg.delete'/>','error');
                return null;
            }
        }
        function add_() {
            href = '${path}/sys/user/addUI.do';
            title : '<spring:message code='msg.create'/>';
            append();
        }
        function modify_(){
            var rows = datagrid.datagrid("getSelections");
            if(!isChooseOne(rows)){return;}
            href = '${path}/sys/user/modifyUI.do?id='+rows[0]['id'];
            title : '<spring:message code='msg.modify'/>'
            append();
        }
        function delete_(){
            var ids = getSelectedIds();
            $.messager.confirm(
                    '<spring:message code='msg'/>',
                    '<spring:message code='msg.confirm.delete'/>',
                    function(r){
                        if (r && null!=ids){
                            imonJYRH.showZone();
                            $.ajax({
                                url : imonJYRH.url("${path}/sys/user/ajaxDelete.do"),
                                cache : false,
                                data :{'ids':ids.join(',')},
                                success : function(reMsg) {
                                    if(reMsg.success){
                                        search_();
                                        message.show({
                                            msg : reMsg.msg,
                                            title : '<spring:message code='msg.tip'/>',
                                            showType:'slide'
                                        });
                                    }else{
                                        message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
                                    }
                                    imonJYRH.hideZone();
                                }
                            });
                        }
                    });
        }
        function search_() {
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('load', imonJYRH.serializeObject($("#tableForm *")));
        }
        function reset_(){
            $("#tableForm *").each(function(){
                $(":input:not(:checkbox,:radio)",this).val("");
            });
        }
    </script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" style="overflow: hidden;height: 86px;">
    <div class="datagrid-toolbar" style="height: auto">
        <br/>
        <fieldset>
            <legend><spring:message code="label.condition"/></legend>
            <table id="tableForm" class="tableForm" width="100%">
                <tr>
                    <td align="right"><spring:message code="label.user.code"/>：</td>
                    <td>
                        <input type="text" name="code"/>
                    </td>
                    <td align="right"><spring:message code="label.user.name"/>：</td>
                    <td>
                        <input type="text" name="name"/>
                    </td>
                    <td align="right"><spring:message code="label.user.state"/>：</td>
                    <td>
                        <select name="state" class="easyui-combobox" data-options="panelHeight:'auto',editable:false">
                            <option value=""><spring:message code='label.all'/></option>
                            <c:forEach var="dict" items="${dictBaseDataStatusList}">
                                <c:choose>
                                    <c:when test='${dict.code==1}'>
                                        <option value="${dict.code}" selected="true">${dict.name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${dict.code}">${dict.name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
            </table>
        </fieldset>
        <br/>
    </div>
</div>
<div data-options="region:'center'">
    <div id="tb">
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-search" onclick="search_();"><spring:message code="bar.command.search"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-undo" onclick="reset_();"><spring:message code="bar.command.reset"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-add" onclick="add_();"><spring:message code="bar.command.add"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-edit" onclick="modify_();"><spring:message code="bar.command.modify"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-edit" onclick="editRoles();"><spring:message code="bar.command.modify"/></a>
        
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-cancel" onclick="delete_();"><spring:message code="bar.command.delete"/></a>
    </div>
    <table id="datagrid" width="100%"  data-options="toolbar:'#tb',striped:true,fit:true,pagination:true,idField:'id',rownumbers:true">
        <thead>
        <tr>
            <th data-options="checkbox:'true',field:'ck'"></th>
            <th data-options="align:'center',width:'120',field:'code'"><spring:message code="table.head.user.code"/></th>
            <th data-options="align:'center',width:'180',field:'name'"><spring:message code="table.head.user.name"/></th>
            <th data-options="align:'center',width:'140',field:'mail'"><spring:message code="table.head.user.mail"/></th>
            <th data-options="align:'center',width:'140',field:'fax'"><spring:message code="table.head.user.fax"/></th>
            <th data-options="align:'center',width:'140',field:'phone'"><spring:message code="table.head.user.phone"/></th>
            <th data-options="align:'center',width:'140',field:'state',formatter:stateFormatter"><spring:message code="table.head.user.state"/></th>
        </tr>
        </thead>
    </table>
</div>
<div id="operateDialog" class="easyui-dialog"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='operateIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
</body>
</html>